home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / metkit / m4string.h < prev    next >
C/C++ Source or Header  |  1997-06-07  |  3KB  |  102 lines

  1. //    Copyright (C) 1996, 1997 Meta Four Software.  All rights reserved.
  2. //
  3. //    This file contains the declaration of the optional string class.
  4. //
  5. //! rev="$Id: m4string.h,v 1.7 1997/05/25 20:00:46 jcw Rel $"
  6.  
  7. #ifndef __M4STRING_H__
  8. #define __M4STRING_H__
  9.  
  10. /////////////////////////////////////////////////////////////////////////////
  11. // Declarations in this file
  12.  
  13.     class c4_String;                    // general string handling class
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Yet another string class (protocol similar to MFC)
  17.  
  18. class c4_String
  19. {
  20. public:
  21.     c4_String ();
  22.     c4_String (char ch, int nDup =1);
  23.     c4_String (const char* str);
  24.     c4_String (const unsigned char* str);
  25.     c4_String (const void* ptr, int len);
  26.     c4_String (const c4_String& s);
  27.     ~c4_String ();
  28.  
  29.     const c4_String& operator= (const c4_String&);
  30.  
  31.     operator const char* () const;
  32.     operator const unsigned char* () const;
  33.     
  34.     char operator[] (int i) const;
  35.     
  36.     friend c4_String operator+ (const c4_String&, const c4_String&);
  37.     friend c4_String operator+ (const c4_String&, const char*);
  38.     friend c4_String operator+ (const char*, const c4_String&);
  39. //    friend c4_String operator+ (const c4_String&, char);
  40. //    friend c4_String operator+ (char, const c4_String&);
  41.  
  42.     const c4_String& operator+= (const c4_String& s);
  43.     const c4_String& operator+= (const char* s);
  44. //    const c4_String& operator+= (char c);
  45.     
  46.     int GetLength() const;
  47.     bool IsEmpty() const;
  48.     void Empty(); // free up the data
  49.     
  50.     c4_String Mid(int nFirst, int nCount =25000) const;
  51.     c4_String Left(int nCount) const; // first nCount chars
  52.     c4_String Right(int nCount) const; // last nCount chars
  53.                     
  54.     friend bool operator== (const c4_String&, const c4_String&); // memcmp
  55.     friend bool operator!= (const c4_String&, const c4_String&); // opposite
  56.     
  57.         // only defined for strings having no zero bytes inside them:
  58.         
  59.     int Compare(const char* str) const; // strcmp
  60.     int CompareNoCase(const char* str) const; // stricmp
  61.     
  62.     bool operator< (const c4_String& str) const;
  63.  
  64.     int Find(char ch) const; // strchr
  65.     int ReverseFind(char ch) const; // strrchr
  66.     int FindOneOf(const char* set) const; // strpbrk
  67.     
  68.     int Find(const char* sub) const; // strstr
  69.     
  70.     c4_String SpanIncluding(const char* set) const; // strspn
  71.     c4_String SpanExcluding(const char* set) const; // strcspn
  72.     
  73. private:
  74.     void Init(const void* p, int n);
  75.     const char* Data() const;
  76.     int FullLength() const;
  77.     
  78.     unsigned char* _value;
  79. };
  80.  
  81. bool operator== (const c4_String& s1, const char* s2);
  82. bool operator== (const char* s1, const c4_String& s2);
  83.  
  84. bool operator!= (const c4_String& s1, const char* s2);
  85. bool operator!= (const char* s1, const c4_String& s2);
  86.  
  87. //    bool operator== (const c4_String& s1, char s2);
  88. //    bool operator== (char s1, const c4_String& s2);
  89.  
  90. //    bool operator!= (const c4_String& s1, char s2);
  91. //    bool operator!= (char s1, const c4_String& s2);
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94.  
  95. #if q4_INLINE
  96.     #include "m4string.inl"
  97. #endif
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100.  
  101. #endif
  102.